package cn.itcast.xuesheng.web.servlet;

import cn.itcast.xuesheng.domain.Topic;
import cn.itcast.xuesheng.service.ShowPageService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

//@WebServlet("/context/*")
@Controller
@RequestMapping("/context")
public class ContextServlet extends BaseServlet {
    private ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");

    //    protected void show(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    @RequestMapping("/show")
    public @ResponseBody Topic show(String tid) {
//        String tid = request.getParameter("tid");
//        ShowpageServiceImpl showpageService=new ShowpageServiceImpl();
        ShowPageService showpageService = (ShowPageService) ac.getBean("showpageService");
        Topic topic = showpageService.show(tid);
        return topic;
    }

    //    protected void totalthumb(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    @RequestMapping("/totalthumb")
    public @ResponseBody List<Topic> totalthumb() {
//        ShowpageServiceImpl showpageService=new ShowpageServiceImpl();
        ShowPageService showpageService = (ShowPageService) ac.getBean("showpageService");
        List<Topic> findthumb = showpageService.findthumb();
//        writeValue(response, findthumb);
        return findthumb;
    }

}
